#include <stdio.h>
#define _XOPEN_SOURCE 
#define __USE_XOPEN
#include <time.h>

unsigned short hj212_crc16(char *data, unsigned int length)
{
    if (NULL == data || 0 == length) return 0;

    unsigned short j, check;
    unsigned short crc_reg = 0xFFFF;
    unsigned int i;

    for (i = 0; i < length; i++)
    {
        crc_reg = (crc_reg >> 8) ^ data[i];
        for (j = 0; j < 8; j++)
        {
            check = crc_reg & 0x0001;
            crc_reg >>= 1;
            if (check == 0x0001)
            {
                crc_reg ^= 0xA001;
            }
        }
    }

    return crc_reg;
}


char* local_t_h212t(const char* t)
{
    static char buf[32] = {0};
    struct tm m_tm;
    //字符串转时间

    strptime(t,"%Y-%m-%d %H:%M:%S",&m_tm);
    strftime(buf, 32, "%Y%m%d%H%M%S", &m_tm);
    //printf("hj212 time %s --> %s",t, buf);
    return buf;
}

void get_local_time(time_t time, char* str)
{
    struct tm *tmTime;
    tmTime = localtime(&time);
    strftime(str, 32, "%Y-%m-%d %H:%M:%S", tmTime);
    //printf("local time is %s\n", str);
}

void get_local_ago_time(time_t time, char* str)
{
    struct tm *tmTime;

    time = time - 3600;

    get_local_time(time, str);
    //printf("local atime is %s\n", str);
}
